import { PageContainer } from '@ant-design/pro-components';
import { Input } from 'antd';
import * as XLSX from 'xlsx';

const Index: React.FC = () => {
  const handleChange = (e: any) => {
    const file = e.target.files[0];

    // 固定写法
    const reader = new FileReader();
    reader.readAsBinaryString(file);
    reader.onload = () => {
      const workbook = XLSX.read(reader.result, { type: 'binary' });
      let res = workbook.Sheets['产品列表'];
      res = XLSX.utils.sheet_to_json(res);

      console.log(res);
    };
  };

  return (
    <PageContainer
      ghost
      header={{
        title: '文件导入',
      }}
    >
      <Input type="file" onChange={handleChange} />
    </PageContainer>
  );
};

export default Index;
